package org.darkforest.task;

import org.darkforest.common.services.GoodsCommonService;
import org.darkforest.common.services.GoodsService;
import org.darkforest.common.services.MessageAndNoticeService;
import org.darkforest.common.util.DateUtil;
import org.darkforest.dao.mapper.GoodsMapper;
import org.darkforest.model.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Libing on 2015/7/8.
 */
@Component
public class GoodsQuartz {

    @Autowired
    private GoodsCommonService goodsCommonService;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private MessageAndNoticeService messageAndNoticeService;

//    @Scheduled(cron = "0 0/3 * * * ?")
//    public void GoodsGrounding(){
//        System.out.println("商品定时上架 每5分钟执行一次:" + new Date());
//        Map<String,Object> map = new HashMap<String,Object>();
//        map.put("nowDate", DateUtil.unixTimeStampInt().intValue());
//        map.put("state",0);
//        goodsCommonService.GroundingGoods(map);
//
//    }


//    @Scheduled(cron = "0 0/5 * * * ?")
//    public void GoodsUndercarriage(){
//        System.out.println("商品定时下架 每5分钟执行一次:" + new Date());
//
//    }

    /*****
     * 商品库存预警
     */
//    @Scheduled(cron = "0 0/3 * * * ?")
    public void GoodsStorageAlarm(){
        List<Goods> list = goodsMapper.selectGoodsStorageAlarm();
        for(Goods goods:list){
            messageAndNoticeService.sendGoodsStorageAlarmToStore(goods);
        }
    }
}
